#!/bin/sh
if [ $# -lt 1 ] 
then
    echo "Usage: ./stat_in_link.sh srcFile";
    echo "File structure:"
    echo "id1""\t""id2,id3,id4"
    exit 1;
else
    src_file=$1
fi

awk '{
    split($2, relates, ",");
    for (id in relates) {
        if (length(relates[id]) < 1) continue;
        if (relates[id] in count_ret) {
            ++count_ret[relates[id]];
        }
        else {
            count_ret[relates[id]] = 1;
        }
    }
}
END {
    for (qId in count_ret) {
        print qId, count_ret[qId];
    }
}' $src_file
